import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import { AtButton, } from 'taro-ui'
import { DNavBar } from '@/components'
import http from '@/api'
import './index.scss'
import { handlePhone } from '@/utils'

export default class EnterpriseAudit extends Component {
    state = {
        employeeApprList: [],
        entId: ''
    }

    componentDidMount() {
        let { entId } = this.$router.params
        this.searchEmployeeApprList(entId)
        this.setState({
            entId
        })
    }

    async searchEmployeeApprList(entId) {
        let { list: employeeApprList } = await http.searchEmployeeApprList({ entId })
        this.setState({
            employeeApprList
        })
    }

    async handleAppro(active) {
        let { isAppro, item } = active
        let params = {
            isAppro,
            creatorId: item.creatorId,
            id: item.id
        }

        await http.reviewEmployee(params)
        console.log(this.state.entId);
        this.searchEmployeeApprList( this.state.entId)
    }

    render() {
        const { employeeApprList } = this.state

        return (
            <View className="my_enterprise_audit">
                <DNavBar title="申请审核"></DNavBar>

                <View className="container">
                    {
                        employeeApprList.map((item, index) => <View className="audit_item">
                            <View className="top">
                                <View className="top_time">申请时间：{item.createTime}</View>
                                <View className="name_moblie">
                                    <Text className="name">{item.creator}</Text>
                                    <Text className="moblie">{handlePhone(item.creatorContact)}</Text>
                                </View>
                                <View className="company">申请加入您所在的【{item.entName}】</View>
                            </View>

                            <View className="bottom">
                                {
                                    item.maIsAppro == 0 && <View className="btns">
                                        <View className="btn cancel" onClick={this.handleAppro.bind(this, { item, isAppro: 0 })}>拒绝</View>
                                        <View className="btn confrim" onClick={this.handleAppro.bind(this, { item, isAppro: 1 })}>同意</View>
                                    </View>
                                }

                                {
                                    (item.maIsAppro == 1 || item.maIsAppro == 2) && <View className="status">
                                        <Text className="status_text">该申请已由{item.updator}审批</Text>
                                        <Text
                                            className={['status_tag', item.maIsAppro == 1 ? 'passed' : "refused"].join(' ')}
                                        >{item.maIsAppro == 1 ? '已通过' : '已拒绝'}</Text>
                                    </View>
                                }


                            </View>
                        </View>)
                    }
                </View>
            </View>
        )
    }
}
